<?php

namespace app\common\model\setting;

use app\common\util\SingleObjectClass;
use think\facade\Cache;

class TraceIDSetting extends SingleObjectClass
{
    private static int $traceId = 0;

    /**
     * 获取trace_id
     * @return int
     */
    public function getTraceID(): int
    {
        if (self::$traceId) {
            return self::$traceId;
        }
        $traceId = Cache::get('trace_id');
        if (!$traceId) {
            $traceId = 10000;
            Cache::set('trace_id', $traceId);
        }
        return $traceId;
    }

    /**
     * 更新trace_id
     * @return void
     */
    public function update(): void
    {
        $this->getTraceID();
        Cache::inc('trace_id',1);
    }

}